﻿using HuChaHuRen.HeNan.XiangCheng.Models.Others;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HuChaHuRen.HeNan.XiangCheng.Common
{
    public class ConfigHelp
    {
        private static readonly string baseConfigPath = $"Config\\base.json";
        private static BaseConfig _baseCfg = null;

        public static BaseConfig GetBaseConfig()
        {
            string configFileFullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, baseConfigPath);
            if (_baseCfg == null)
            {
                if (!File.Exists(configFileFullPath))
                {
                    throw new FileNotFoundException($"配置文件未找到: {configFileFullPath}");
                }
                else
                {
                    string json = File.ReadAllText(configFileFullPath);
                    _baseCfg = JsonConvert.DeserializeObject<BaseConfig>(json);
                }
                
            }
            return _baseCfg;
        }

        public static void OpenConfigDir()
        {
            string configDirFullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config");
            if (Directory.Exists(configDirFullPath))
            {
                System.Diagnostics.Process.Start("explorer.exe", configDirFullPath);
            }
        }
    }
}
